package com.r2coding.music.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.r2coding.common.util.Result;
import com.r2coding.music.entity.SonglistCommentEntity;
import com.r2coding.music.service.SonglistCommentService;
import com.r2coding.music.vo.req.SongListCommentReqVo;
import com.r2coding.music.vo.resp.SongListCommentRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:98k灬
 * @since:2022/05/20 21:14
 **/
@RestController
@RequestMapping("/api/songlistcomment")
public class ApiSonglistCommentController {
    @Autowired
    SonglistCommentService songlistCommentService;

    /**
     * 发表评论
     *
     * @param songlistComment 评论信息
     * @return 统一响应体
     */
    @PostMapping("/save")
    public Result save(@RequestBody SonglistCommentEntity songlistComment) {
        songlistCommentService.saveComment(songlistComment);
        return Result.ok();
    }

    /**
     * 根据歌单id查询该歌单下所有的评论信息
     *
     * @param reqVo 请求信息
     * @return 统一响应体
     */
    @PostMapping("/getAll")
    public Result getAll(@RequestBody SongListCommentReqVo reqVo) {
        List<SongListCommentRespVo> list = songlistCommentService.getAll(reqVo);
        return Result.ok(list);
    }

    /**
     * 根据歌单id查询该歌单的评论数量
     *
     * @param songlistId 歌单id
     * @return 统一响应体
     */
    @GetMapping("/getCommentCount/{songlistId}")
    public Result getCommentCount(@PathVariable("songlistId") Integer songlistId) {
        int count = songlistCommentService.count(new QueryWrapper<SonglistCommentEntity>().eq("songlist_id", songlistId));
        return Result.ok(count);
    }
}
